package com.example.chao.myphotosearch.presenter;

import com.example.chao.myphotosearch.api.HttpRetrofit;
import com.example.chao.myphotosearch.api.HttpSubscribe;
import com.example.chao.myphotosearch.bean.ImageJoy;
import com.example.chao.myphotosearch.interfaces.SubscriberDoOnNextListener;
import com.example.chao.myphotosearch.view.ISwipeView;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by chao on 2016/4/27.
 */
public class JoyFragmentPresenter implements IPresenter<ISwipeView<List<ImageJoy>>>{
    private ArrayList<ImageJoy> joys;
    private ISwipeView<List<ImageJoy>> iSwipeView;
    @Inject
    public JoyFragmentPresenter(){
        joys = new ArrayList<>();
    }

    @Override
    public void onCreate(ISwipeView<List<ImageJoy>> iView) {
        iSwipeView = iView;
        onViewCreated();
    }

    @Override
    public void onViewCreated() {
        HttpRetrofit.getImageJoys(new HttpSubscribe<ArrayList<ImageJoy>>(new SubscriberDoOnNextListener<ArrayList<ImageJoy>>() {
            @Override
            public void doOnNext(ArrayList<ImageJoy> joyArrayList) {
                joys = joyArrayList;
                iSwipeView.attachView(joys);
            }
        }));
        iSwipeView.hideRefresh();
    }
}
